package SecondSaturday;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ChulHistory extends JFrame {
	Chul[] chul;
	int pos=0;
	boolean flag=false;
	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JScrollPane scrollPane;
	private JTextArea result;
	
	public ChulHistory(Chul[] chul,int h, boolean c) {
		this.pos = h;
		this.flag=c;
		this.chul=chul;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setTitle("History of Chul");
		setBounds(100, 100, 288, 457);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getScrollPane());
		output_2();
		
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("출석 기록");
			lblNewLabel.setBounds(12, 10, 57, 15);
		}
		return lblNewLabel;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 34, 248, 375);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}
	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		chulManage cm = new chulManage();
		for(int i=0;i<cm.hist.length;i++){
			result.append(cm.hist[i]);
		}
		
		return result;
	}
	public void output(){
		result.setText("");
			
		for(int i=0;i<chul.length;i++){
			if(chul[i]!=null){
				result.append(chul[i].toString()+"\n");
			}		
		}
	}
	public void output_2(){
		result.setText("");
		for(int i=pos-1; i>=0; i--){
			String temp = (chul[i].CheckIn != null)?"출근":"퇴근";
			result.append(chul[i].toString() + temp + "\n");
		}
		if(flag){ // 반복되었다면,
			for(int i=chul.length-1;i>=pos;i--){
				String temp = (chul[i].CheckIn != null)?"출근":"퇴근";
				result.append(chul[i].toString() + temp + "\n");
			}
		}
		
	}
}
